# -*- coding: utf-8 -*-
import smtplib
from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
from email.mime.base import MIMEBase 
from email.mime.multipart import MIMEMultipart
import time



def send_email_file(subject,filePath):
    from_addr='251171826@qq.com'
    password=''#邮箱的 开通发送服务的密码
    to_addr = 'chenzg@ct108.com'
    msg = MIMEMultipart()
    msg['From'] = from_addr
    msg['To'] = to_addr
    msg['Subject'] = subject

    
    att1 = MIMEText(open(filePath, 'rb').read(), 'xls', 'gb2312')
    att1["Content-Type"] = 'application/octet-stream'
    att1["Content-Disposition"] = 'attachment;filename=baidu.xls'
    msg.attach(att1)

    smtp = smtplib.SMTP_SSL('smtp.qq.com', 465)
    smtp.set_debuglevel(1)
    smtp.ehlo('smtp.qq.com')
    smtp.login(from_addr, password)
    smtp.sendmail(from_addr, [to_addr], msg.as_string())

def send_email(title,msg):
    from_addr='251171826@qq.com'
    password=''#邮箱的 开通发送服务的密码
    to_addr = 'chenzg@ct108.com'
    msg = MIMEText(msg, 'plain', 'utf-8')
    msg['From'] = from_addr
    msg['To'] = to_addr
    msg['Subject'] = title

    smtp = smtplib.SMTP_SSL('smtp.qq.com', 465)
    smtp.set_debuglevel(1)
    smtp.ehlo('smtp.qq.com')
    smtp.login(from_addr, password)
    smtp.sendmail(from_addr, [to_addr], msg.as_string())

if __name__ == "__main__":
    send_email("畅唐测试平台定时任务",'test')